#！ /usr/bin/python3
# coding=UTF-8

from os import kill
import sqlite3


conn = sqlite3.connect('./shiti.db')
cur = conn.cursor()

cur.execute('select * from exam')
values = cur.fetchall()
cur.close()
conn.close()

import tkinter
from tkinter import *
from tkinter.messagebox import *

def callNext():
    global k
    global score
    useranswer = r.get()
    print(r.get())
    if useranswer == values[k][5]:
        showinfo('恭喜','恭喜你答对了')
        score += 10
    else:
        showinfo('错误','答案错误')
    k += 1
    if k>=len(values):
        showinfo('答题完毕')
        return
    timu['text']= values[k][0]
    radio1['text']=values[k][1]
    radio2['text']=values[k][2]
    radio3['text']=values[k][3]
    radio4['text']=values[k][4]
    r.set('E')

def callResult():
    showinfo('你的得分',str(score))

if __name__ == '__main__':
    root = Tk()
    root.title('智力问答')
    root.geometry('500x200')
    r = tkinter.StringVar()
    r.set('E')
    k = 0
    score = 0
    timu = tkinter.Label(root, text=values[k][0])  #题目
    timu.pack()
    f1 = Frame(root)  #创建第一个Frame组件
    f1.pack()
    radio1 = tkinter.Radiobutton(f1, variable=r, value='A',text = values[k][1])
    radio1.pack()
    radio2 = tkinter.Radiobutton(f1, variable=r, value='B',text = values[k][2])
    radio2.pack()
    radio3 = tkinter.Radiobutton(f1, variable=r, value='C',text = values[k][3])
    radio3.pack()
    radio4 = tkinter.Radiobutton(f1, variable=r, value='D',text = values[k][4])
    radio4.pack()
    f2 = Frame(root)   #创建第二个Frame组件
    f2.pack()
    Button(f2, text="下一题", command=callNext).pack(side=LEFT)
    Button(f2, text='结  果',command=callResult).pack(side=LEFT)
    root.mainloop()